define(function(require){
	var main =require('/static/main.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		_init:function(){
		    m.loadmenu('.cate-drainage',5);
		    this.getlist();
			this.bindEvent();
		},
		bindEvent:function(){
			
		},
		getlist:function(){
	        var param = {};
	        var sort = 0;
	        var table1 = $('#datatable').dataTable({
	        	'ordering':false,
	        	"serverSide": true,
	        	"searching":false,
	        	'bLengthChange': false,
	        	"scrollX": true,
	        	ajax: function (data, callback, settings) {
	                param.PageSize = data.length;
	                param.start = data.start;
	                param.PageNo = (data.start / data.length)+1;
	                $.ajax({
	                    type: "POST",
	                    url: "/drainage/group-list",
	                    cache: false,  
	                    data: param, 
	                    dataType: "json",
	                    success: function (result) {
                    	    var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            callback(returnData);
	                    }
	                });
	            },
				"aoColumns":[
					{
						"mDataProp": 'ActGroupId',
						render:function(data){
							sort ++;
                    		return sort;
                    	}
					}, 
					{
			            "mDataProp": "ActGroupId",
			            "sClass": "option_btn",
			            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            	// console.log(arguments);
			                $(nTd).html('<div data-toggle="modal" data-target="#con-close-modal" style="display: inline-block;">\
                                                  <a href="/drainage/groupcreate?id='+sData+'"><span class="btn_edit" >编辑</span></a>\
                                                  <span class="btn_del" id='+sData+'>删除</span>\
                                                  <a href="/drainage/grouptracking?id='+sData+'"><span class="btn_flow" >活动报名跟踪</span></a>\
                                                </div>');

			            }
			        },
					{
						"mDataProp": 'CoverSrc',
						"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;max-height:70px;">')
			            }
					},
					{
                    	"mDataProp": 'ActName',
                   	}, 
                    // {
                    // 	"mDataProp": 'Comment',
                    // 	"sClass": "avtivedes ",
                   	// }, 
                   	// {
                    // 	"mDataProp": 'GameRule',
                   	// },
                   	// {
                    // 	"mDataProp": 'PlayingDescribe',
                   	// },
                   	{
						"mDataProp": 'ProductSrc',
						"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;max-height:70px;">')
			            }
					},
					{
                    	"mDataProp": 'ProductName',
                   	},
                   	{
                    	"mDataProp": 'BounsPrdType',
                    	// paidn
                   	},
                   	{
                    	"mDataProp": 'OriginalPrice',
                   	},
                   	{
                    	"mDataProp": 'GroupPrice',
                   	},
                   	{
                    	"mDataProp": 'GroupPeriod',
                   	},
                   	{
                    	"mDataProp": 'GroupScale',
                   	},
                   	{
                    	"mDataProp": 'DeliveryType',
                    	render:function(data){
                    		if(data == 300){
                    			return '线上物流发货（实物产品）'
                    		}else if(data == 200){
                    			return '线下门店自提（实物产品）'
                    		}else{
                    			return '系统自动处理（虚拟产品）'
                    		}
                    	}
                   	},
                   	{
                    	"mDataProp": 'ReceiveAdd',
                   	},
                   	{
                    	"mDataProp": 'NoticeTel',
                   	},
                   	{
                    	"mDataProp": 'Hotline',
                   	},

                   	{
                    	"mDataProp": 'JoinCnt',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'GroupCnt',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'SurplusCnt',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'PayCnt',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'RefundCnt',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'PayAmount',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'RefundAmount',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'ShareCount',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},
                   	{
                    	"mDataProp": 'ReadCount',
                    	render:function(data){
                    		return data ? data : 0;
                    	}
                   	},

                   	{
                    	"mDataProp": 'QRCode',
                    	"sClass": "show_QRCode",
                    	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;height:100px;">')
			            }
                   	},
                   	{
                    	"mDataProp": 'IsOpen',
                    	render:function(data){
                    		return data ? '开启' : '未开启'
                    	}
                   	},
                    {
                    	"mDataProp": 'StartTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '';
                    		}
                    	}
                	},
                	{
                    	"mDataProp": 'EndTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '';
                    		}
                    	}
                	},
       //          	{
       //              	"mDataProp": 'ShareSrc',
       //              	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							// $(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;max-height:70px;">')
			    //         }
       //             	},

				],
	        }).api();
			// 点击搜索
	        $('#btnSearch').click(function(){
	        	param.ActName = $('.ActName').val();
	        	if($('.IsOpen option:selected').val() != 0){
	        		param.IsOpen = $('.IsOpen option:selected').val();
	        	}else{
	        		param.IsOpen = ''
	        	}
	        	param.StartTime = $('.StartTime').val()
	        	param.EndTime = $('.EndTime').val()
	        	sort = 0;
                table1.ajax.reload();
	        })
	        // 点击重置按钮
	        $('#btnRefresh').click(function(){
	        	$('.IsOpen option').each(function(){
					if($(this).val() == 0){
						$(this).attr('selected',true);
					}else{
						$(this).attr('selected',false);
					}
				})
	        	$('.ActName').val('');
	        	$('.StartTime').val('');
	        	$('.EndTime').val('');
	        })
	        // 点击删除
	        $(document).on('click','.btn_del',function(){
  	        	var id = $(this).attr('id');
  	        	layer.confirm('是否删除该活动？', {
  				  btn: ['确定','取消'] //按钮
  				}, function(){
  				  	$.ajax({
                  type: "POST",
                  url:'/drainage/group-del',
                  data:{ActGroupId:id},
                  dataType: "json",
                  success: function (ret) {
              	  	if(ret.IsBizSuccess){
		                layer.msg('删除成功');
		                sort = 0;
		                table1.ajax.reload();
              	  	}else{
              	  		layer.msg(ret.ErrMsg);
              	  		return false;
              	  	}
                  }
              });
  				});
	        })
		},

	}
	var a = new Cont();

})